import execjs
import requests
import re

headers = {
    "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
    "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",
    "Cache-Control": "no-cache",
    "Connection": "keep-alive",
    "Pragma": "no-cache",
    "Referer": "https://xueqiu.com/today",
    "Sec-Fetch-Dest": "document",
    "Sec-Fetch-Mode": "navigate",
    "Sec-Fetch-Site": "same-origin",
    "Sec-Fetch-User": "?1",
    "Upgrade-Insecure-Requests": "1",
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36 Edg/127.0.0.0",
    "sec-ch-ua": "\"Not)A;Brand\";v=\"99\", \"Microsoft Edge\";v=\"127\", \"Chromium\";v=\"127\"",
    "sec-ch-ua-mobile": "?0",
    "sec-ch-ua-platform": "\"Windows\""
}
cookies = {

}

# "acw_tc": "2760827117240850021826471ea878392557abec9846e6da4ff413c884b7dc",
# "acw_sc__v2": "66c3730a99da2bb050aedbb5c9ea9863e8c83a19",

url = "https://xueqiu.com/today"
response = requests.get(url, headers=headers, cookies=cookies)
print(response.text)

print("-" * 100)

arg1 = re.findall("var arg1='(.*?)';", response.text)[0]
acw_tc = response.cookies.get("acw_tc")
acw_sc__v2 = execjs.compile(open('./main.js', 'r', encoding='utf-8').read()).call('main', arg1)
cookies['acw_sc__v2'] = acw_sc__v2

url = "https://xueqiu.com/today"
response = requests.get(url, headers=headers, cookies=cookies)
print(response.text)
